#include<bits/stdc++.h>
#define endl '\n'
#define debug(x) cerr<<#x<<':'<<x<<endl
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N=2e5+5;
int T,p,n;
int f[N][455];
void solve(){
	cin>>n;
	int ans=0;
	for(int i=1;i*i<=n;i++)
        if(!((n-i*i)&1))
            ans=(ans+f[(n-i*i)>>1][i])%p;
	cout<<ans<<endl;
}
signed main(){
  	freopen("moon.in","r",stdin);
  	freopen("moon.out","w",stdout);
    IOS;
	cin>>T>>p;
	for(int i=0;i<=450;i++) f[0][i]=1;
  	for(int i=1;i<=200000;i++){
	  	for(int j=1;j<=min(450,i);j++) f[i][j]=f[i-j][j];
	  	for(int j=1;j<=450;j++) f[i][j]=(f[i][j]+f[i][j-1])%p;
	}
	while(T--) solve();
    return 0;
}
